package csse3004.GD.PM;

/**
 * @author Mamdouh Alharbi s4194298
 */
import org.springframework.validation.Validator;
import org.springframework.validation.Errors;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class OpenCloseValidator implements Validator {

    protected final Log logger = LogFactory.getLog(getClass());

    public boolean supports(Class clazz) {
        return OpenClose.class.equals(clazz);
    }

    public void validate(Object obj, Errors errors) {

        OpenClose searchy = (OpenClose) obj;
        String searchword = searchy.getSearchword();

        logger.info("Checking Empty String");
        logger.info(searchword);

        if (searchword.isEmpty()) {
            errors.rejectValue("searchword", "error.not-specified", null, "Search Word is Required.");
        } else {
            logger.info("Trying to search");
        }
    }
}
